package com.pin.zheng.xingmulibrary.view;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

public class MyTextView1 extends AppCompatTextView {
    private String type = "fonts/DIN.otf";
    private Context context;

    public MyTextView1(@NonNull Context context) {
        super(context);
        this.context = context;
        //设置字体
        init(context);
    }

    public MyTextView1(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        //设置字体
        init(context);
    }

    public MyTextView1(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        //设置字体
        init(context);
    }

    public void setType(String type) {
        this.type = type;
        init(context);
    }

    private void init(Context mContext) {
        Typeface tf = Typeface.createFromAsset(mContext.getAssets(), type);
        setTypeface(tf);
    }
}
